﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PowerHub.MES.ReturnEntity
{
    /// <summary>
    /// 返回实体分页类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class OperationPageResult<T> : PageQuery
    {
        /// <summary>
        /// 状态结果
        /// </summary>
        public ResultStatus.GetResultStatus Status { get; set; } = ResultStatus.GetResultStatus.Success;

        private string? _msg = "一切ok";

        /// <summary>
        /// 消息描述
        /// </summary>
        public string? Message
        {
            get
            {
                // 如果没有自定义的结果描述，则可以获取当前状态的描述
                return !string.IsNullOrEmpty(_msg) ? _msg : EnumHelper.GetDescription(Status);
            }
            set
            {
                _msg = value;
            }
        }

        /// <summary>
        /// 返回结果
        /// </summary>
        public T Data { get; set; }

   

        /// <summary>
        /// 隐式将T转化为ResponseResult<T>
        /// </summary>
        /// <param name="value"></param>
        //public static implicit operator OperationPageResult<T>(T value)
        //{
        //    return new OperationPageResult<T> { Data = value };
        //}

        /// <summary>
        /// 隐式将T转化为ResponseResult<T>
        /// </summary>
        /// <param name="value"></param>
        public static OperationPageResult<T> Result(ResultStatus.GetResultStatus status, T data, string? msg = null)
        {
            return new OperationPageResult<T> { Status = status, Data = data, Message = msg };
        }
    }
}
